{% if is_paginated %}
<ul class="pagination">
    {% if page_obj.has_previous %}
    <li class="page-item">
        <a class="page-link" href="?page=1">首页</a>
    </li>
    <li class="page-item">
        <a class="page-link" href="?page={{ page_obj.previous_page_number }}">&laquo;</a>
    </li>
    {% endif %}

    {% for num in page_obj.paginator.page_range %}
    {% if page_obj.number == num %}
    <li class="page-item active">
        <a class="page-link" href="?page={{ num }}">{{ num }}</a>
    </li>
    {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
    <li class="page-item">
        <a class="page-link" href="?page={{ num }}">{{ num }}</a>
    </li>
    {% endif %}
    {% endfor %}

    {% if page_obj.has_next %}
    <li class="page-item">
        <a class="page-link" href="?page={{ page_obj.next_page_number }}">&raquo;</a>
    </li>
    <li class="page-item">
        <a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">尾页</a>
    </li>
    {% endif %}
</ul>
{% endif %}